package com.ruoyi.food.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ruoyi.food.object.TRectInfo;

@Mapper
public interface TRectInfoMapper extends BaseMapper<TRectInfo>{

	public static String sql="SELECT i.RECT_ID,i.ENTERPRISE_NAME,i.INSPECT_UNIT,i.TIKCET_NO,i.REMARK,i.CHECK_TIME,i.RESULT,i.HAS_PUB,i.FINISH_TIME FROM t_rect_info i";
	
	@Select({"<script>",
        sql,
        "WHERE 1=1 and IS_VALID=1",
        "<when test='enterpriseName != \"\" and enterpriseName !=null'>",
        "AND i.ENTERPRISE_NAME like concat('%', #{enterpriseName}, '%')",
        "</when>",
        "<when test='inspectUnit != \"\" and inspectUnit !=null'>",
        "AND i.INSPECT_UNIT like concat('%', #{inspectUnit}, '%')",
        "</when>",
        "<when test='tikcetNo != \"\" and tikcetNo !=null'>",
        "AND i.TIKCET_NO like concat('%', #{tikcetNo}, '%')",
        "</when>",
        "</script>"})
	public List<TRectInfo> selectTRectInfo(TRectInfo tRectInfo);
	
	@Insert("insert into t_rect_info(ENTERPRISE_NAME,INSPECT_UNIT,TIKCET_NO,REMARK,CHECK_TIME,RESULT,HAS_PUB,FINISH_TIME,IS_VALID) "
			+ "values(#{enterpriseName},#{inspectUnit},#{tikcetNo},#{remark},#{checkTime},#{result},#{hasPub},#{finishTime},1)")
	public void insertTRectInfo(TRectInfo tRectInfo);
	
	@Select("SELECT *from t_rect_info where RECT_ID=#{rectId}")
	public TRectInfo selectTRectInfoById(long rectId);
	
	@Update("update t_rect_info set ENTERPRISE_NAME=#{enterpriseName},INSPECT_UNIT=#{inspectUnit},TIKCET_NO=#{tikcetNo},REMARK=#{remark},CHECK_TIME=#{checkTime},RESULT=#{result},HAS_PUB=#{hasPub},FINISH_TIME=#{finishTime} where RECT_ID=#{rectId}")
	public void updateTRectInfo(TRectInfo tRectInfo);
	
	/**
	 * 逻辑删除
	 * @param rectId
	 */
	@Update("update t_rect_info set IS_VALID=0 where RECT_ID=#{rectId}")
	public void deleteTRectInfo(long rectId);
	
	/**
	 * 查询全部整改记录
	 * @return
	 */
	@Select(sql+" WHERE IS_VALID=1")
	public List<TRectInfo> selectAllTRectInfo();
}
